package com.guoyansoft.controller;

import com.guoyansoft.config.GetTimeDifference;
import com.guoyansoft.config.R;
import com.guoyansoft.model.pojo.Administrators;
import com.guoyansoft.model.pojo.HistoricalOrders;
import com.guoyansoft.model.service.AdministratorsService;
import com.guoyansoft.model.service.HistoricalOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘耀诚
 * 平台管理员业务控制器
 */
@RestController
@RequestMapping("/admin")
public class AdministratorsController {
    @Autowired
    private AdministratorsService administratorsService;

    /**
     * 新增平台管理员
     * @param administrators
     * @return 响应结果
     */
    @RequestMapping("/save")
    public R goToHistory(Administrators administrators){
        return administratorsService.save(administrators);
    }

    /**
     * 修改平台管理员
     * @param administrators
     * @return 响应结果
     */
    @RequestMapping("/modify")
    public R modify(Administrators administrators){
        return administratorsService.modify(administrators);
    }

    /**
     * 删除
     * @param id 主键
     * @return 响应结果
     */
    @RequestMapping("/drop")
    public R drop(Integer id){
        return administratorsService.drop(id);
    }

    /**
     * 多条件分页展示
     * @param curPage 当前页
     * @param pageSize 每页记录数
     * @return 响应数据
     */
    @RequestMapping("/queryByPage")
    public R queryByPage(Integer curPage,Integer pageSize){
        Map<String,Object> map=new HashMap<>();
        map.put("startIndex",(curPage-1)*pageSize);
        map.put("pageSize",pageSize);
        return administratorsService.queryByPage(map);
    }
    @RequestMapping("/login")
    public R login(Administrators administrators){
        return administratorsService.queryOfLogin(administrators);
    }
}
